<?php
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('cms.html.toolbar');
 
/**
 * Search Engine Friendly Frontend Buttons
 */
class JToolbarButtonFrontend extends JToolbarButton {
 
        public function fetchButton($type = 'Frontend', $name = '', $text = '', $task = '', $list = true)
        {
                $i18n_text = JText::_($text);
                $class = $this->fetchIconClass($name);
                $doTask = $this->_getCommand($text, $task, $list);
 
                $html = "<button onclick=\"$doTask\" class=\"btn btn-small\">\n";
                $html .= "<span class=\"$class\">\n";
                $html .= "</span>\n";
                $html .= "$i18n_text\n";
                $html .= "</button>\n";
 
                return $html;
        }
 
        /**
     * Get the button CSS Id
     *
     * @param   string  $type  Not used.
     * @param   string  $html  Not used.
     * @param   string  $id    The id prefix for the button.
     *
     * @return  string  Button CSS Id
     *
     * @since   3.0
     */
    public function fetchId($type = 'Frontend', $html = '', $id = 'frontend')
    {
        return $this->_parent->getName() . '-' . $id;
    }
 
        /**
     * Get the JavaScript command for the button
     *
     * @param   string   $name  The task name as seen by the user
     * @param   string   $task  The task used by the application
     * @param   boolean  $list  True is requires a list confirmation.
     *
     * @return  string   JavaScript command string
     *
     * @since   3.0
     */
    protected function _getCommand($name, $task, $list)
    {
        JHtml::_('behavior.framework');
        $message = JText::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
        $message = addslashes($message);
 
        if ($list)
        {
            $cmd = "if (document.adminForm.boxchecked.value==0){alert('$message');}else{ Joomla.submitbutton('$task')}";
        }
        else
        {
            $cmd = "Joomla.submitbutton('$task')";
        }
 
        return $cmd;
 
    }
}

